#ifndef __LINKSTACK_H__
#define __LINKSTACK_H__

#include "Common.h"
#include "Object.h"
#include "Exception.h"
#include "LinkList.h"


NAME_SPACE_BEGIN

template < typename T >
class LinkStack : public Stack<T>
{
public:
	void push(const T& e)  // O(1)
	{
		m_list.insert(0, e);
	}

	void pop()   // O(1)
	{
		if (m_list.length() > 0)
		{
			m_list.remove(0);
		}
		else
		{
			THROW_EXCEPTION(InvalidOperatorException, "No element in current stack ...");
		}
	}

	T top() const  // O(1)
	{
		if (m_list.length() > 0)
		{
			return m_list.get(0);
		}
		else
		{
			THROW_EXCEPTION(InvalidOperatorException, "No element in current stack ...");
		}
	}

	void clear()  // O(n)
	{
		m_list.clear();
	}

	int size() const  // O(1)
	{
		return m_list.length();
	}
protected:
	LinkList<T> m_list;
};


NAME_SPACE_END
#endif

